package com.core.ingenium.view.epadilla;


import com.core.ingenium.model.Bitacora;
import com.core.ingenium.model.JavaServiceFacade;
import com.core.ingenium.model.Usuario;

import java.io.Serializable;

import java.sql.Timestamp;

import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class BitacoraController implements Serializable {
    
    private JavaServiceFacade service;
    private List<Bitacora> lstBitacora;
    
    public BitacoraController() {
        service = new JavaServiceFacade();
        this.setLstBitacora(service.getBitacoraFindAll());
    }

    public boolean registrar(Usuario usuario, String operacion){
        boolean ok = false;
        try{
            Bitacora b = new Bitacora();
            b.setOperacion(operacion);
            b.setUsuario(usuario.getNombre()+" "+usuario.getApellido1()+" "+usuario.getApellido2());
            Calendar c = Calendar.getInstance();
            Date d = c.getTime();
            Timestamp fecha = new Timestamp(d.getTime());
            b.setFecha(fecha);
            
            service.persistBitacora(b);
            ok = true;
            
        }catch(Exception e){
            ok = false;
        }
        
        return ok;
    }


    //setters
    public void setLstBitacora(List<Bitacora> lstBitacora) {this.lstBitacora = lstBitacora;}

    //getters
    public List<Bitacora> getLstBitacora() {return lstBitacora;}
}
